package cn.good.yan.mapper;

import cn.good.yan.pojo.Bill;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 注解版的使用
 *
 * @author shengren.yan
 * @create 2022-12-04
 */
// 指定这是操作数据的Mapper，主启动器有@MapperScan，就不需要 @Mapper
@Repository
public interface BillMapper {

    // useGeneratedKeys是否使用自增主键，keyProperty 指定主键值
    @Options(useGeneratedKeys = true, keyProperty = "bid")
    @Insert("INSERT INTO bill (bid,bill_code,bill_name) VALUES (null,#{billCode},#{billName}) ")
    int add(Bill bill);

    @Update("update bill set pay = 1 where bid = #{bid} ")
    void updateByBid(Long bid);

    @Update("update bill set bill_Name=#{billName} where bid=#{bid}")
    int update(Bill bill);

    @Select("select * from bill where bill_code=#{billCode} ")
    Bill findByBillCode(String billCode);

    @Select(" select * from bill where bid = #{bid} ")
    List<Bill> findByBid(Long bid);

    // 批量查询 ，注意：参数是字符串 1,3,4
    @Select(" select * from bill where bid in (${bids}) ")
    List<Bill> findByBids(String bids);

    @Delete("delete from bill where bid=#{bid}")
    int deletePByPid(Long bid);

    @Select(" select * from bill ")
    List<Bill> findAll();

}
